using Gateway.Common.Extensions;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class RoleConfiguration : AggregateRootEntityConfiguration<Role>
{
    public override void Configure(EntityTypeBuilder<Role> builder)
    {
        builder.ToTable(t => t.HasComment("角色表"));
        base.Configure(builder);
        builder.Property(x => x.RoleAlias).IsRequired().HasMaxLength(200).HasComment("角色别名");
        builder.Property(x => x.RoleName).IsRequired().HasMaxLength(200).HasComment("角色名称");

        builder.Property(x => x.RoleNo).IsRequired().HasMaxLength(50).HasComment("角色编号");
        builder.Property(x => x.Remark).HasMaxLength(500).HasComment("备注");

        builder.Property(x => x.SeqNo).IsRequired().HasComment("序号");


        // 初始化 数据
        var role = new Role("超级管理员", "超级管理员", "");
        role.SetDefaultId();
        role.SetCreate("admin", "admin");
        builder.HasData(role);
    }
}